# import cv2
from PIL import Image
import os
from my_crnn.train_crnn.utils.dataset import Augment

aug = Augment()
new_save_path = 'C:/Users/Administrator/Downloads/zzs_result_aug_v1/'
if not os.path.isdir(new_save_path):
    os.mkdir(new_save_path)
with open(r'C:\Users\Administrator\Downloads\zzs_result_aug_v1\zzs_v2.txt', 'w', encoding='utf-8') as f1:
    with open(r'C:\Users\Administrator\Downloads\zzs_result_v1\zzs_v2.txt','r',encoding='utf-8') as f2:
        lines = f2.readlines()
        for line in lines:
            img_path = line.split(' ')[0]
            label = line.split(' ')[-1].replace('\n','')
            img_name = img_path.split('/')[-1].split('.')[0]
            img = Image.open(img_path).convert('L')
            img_v1 = aug.randomfunction(img)
            sava_path_0 = new_save_path + img_name + '_' + str(0) + '.jpg'
            img_v1.save(sava_path_0, quality=95)
            f1.writelines(sava_path_0 + ' ' + str(label) + "\n")
            f1.flush()
            for i in range(1,11):
                img_v1 = aug.randomfunction(img)
                sava_path = new_save_path+img_name+'_'+str(i)+'.jpg'
                img_v1.save(sava_path, quality=95)
                f1.writelines(sava_path + ' ' + str(label) + "\n")
                f1.flush()